﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TMDbLib.Client;
using TMDbLib.Objects.Collections;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.Search;

namespace Filmi.NonSemantic
{
    public static class YouTubeTrailerGetter
    {
        public static List<string> GetMovieTrailers(string movieName)
        {
            var client = new TMDbClient("b2f323847ae38ebd91ee5d9ca61c1225");
            var trailerSources = new List<string>();
            try
            {
                var movies = client.SearchMovie(movieName);
                foreach (var movie in movies.Results)
                {
                    var trailer = client.GetMovieTrailers(movie.Id);
                    foreach (var youtube in trailer.Youtube)
                    {
                        trailerSources.Add("http://www.youtube.com/watch?v=" + youtube.Source);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
            return trailerSources;
        }
    }
}
